<?php

namespace Amis\Basics;

class AmisBasics implements AmisInterface
{
    public string $type;
    /**
     * @var array
     */
    static protected array $definitions = [];

    /**
     * 静态访问
     * @return static
     */
    public static function Instance()
    {
        return new static();
    }


    /**
     * 设置公共数据参数
     * @param $key
     * @param $value
     * @return bool
     */
    static public function DefinitionsSet($key, $value)
    {
        static::$definitions['definitions'][$key] = $value;
        return true;
    }

    /**
     * 组件运行起始
     * @param $node
     * @return mixed
     */
    public function run($node)
    {
        $node($this);
        return $this;
    }


    /**
     * 通用方法，适合直接传入数组的方式构建
     * @param $key
     * @param $values
     */
    public function set($key, ...$values)
    {
        $nub = func_num_args();

        if ($nub < 3) {
            $this->$key =    $values[0];
        } else {
            $args =   func_get_args();
            array_shift($args);
            if (count($args) < 2) {
                $this->$key =   $args[0];
            } else {
                $this->$key =   $args;
            }
        }
        return $this;
    }



    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    public function __call($methodName, $arges)
    {
        foreach (func_get_args() as $arge) {
            $this->set($methodName, $arge);
        }

        return $this;
    }
}
